package com.ruoyi.common.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * 费率时段类型枚举
 * Enum for Rate Period Types.
 */
@Getter
@AllArgsConstructor
public enum RatePeriodType {
    PEAK(0x00, "尖费率"),
    HIGH(0x01, "峰费率"),
    NORMAL(0x02, "平费率"),
    VALLEY(0x03, "谷费率"),
    UNKNOWN(0xFF, "未知费率");

    private final int code;
    private final String description;

    private static final Map<Integer, RatePeriodType> CODE_MAP = new HashMap<>();

    static {
        for (RatePeriodType type : values()) {
            CODE_MAP.put(type.getCode(), type);
        }
    }

    /**
     * 根据编码获取枚举实例
     * Gets the enum instance from its code.
     *
     * @param code The rate period code (e.g., 0x00, 0x01).
     * @return The corresponding RatePeriodType, or UNKNOWN if not found.
     */
    public static RatePeriodType fromCode(int code) {
        return CODE_MAP.getOrDefault(code, UNKNOWN);
    }
}